package by.jtraining.london.service;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class UtilService {

	private static final Logger LOG = LoggerFactory
			.getLogger(UtilService.class);

	public static String stringToHash(String password)
			throws NoSuchAlgorithmException {
		LOG.info("Start hashing!!!");
		LOG.debug("password={}", password);
		MessageDigest md = MessageDigest.getInstance("MD5");
		md.update(password.getBytes());
		byte byteData[] = md.digest();
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < byteData.length; i++) {
			sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16)
					.substring(1));
		}
		LOG.debug("Hash password={}", sb);
		return sb.toString();
	}

}
